package com.jaiai.work.project.api;

import com.baomidou.mybatisplus.plugins.Page;
import com.jaiai.work.project.entity.*;
import com.jaiai.work.project.service.*;
import com.jaiai.work.util.RestResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2018-04-18
 */
@RestController
@RequestMapping("/project/tProject")
public class TProjectController {

    @Autowired
    private ITProjectService iTProjectService;
    @Autowired
    private ITDictionariesService iTDictionariesService;
    @Autowired
    private ITEntityService iTEntityService;
    @Autowired
    private ITInterfaceService iTInterfaceService;
    @Autowired
    private ITModularService iTModularService;
    @Autowired
    private ITResourceService iTResourceService;

    /**
     * 项目表添加或修改
     * 传入对象
     * */
    @PostMapping("/projectInsertOrUpdate")
    Object projectInsertOrUpdate(@RequestBody TProject tProject)throws Exception{
        try {
            tProject.setCreateTime(new Date());
            return RestResultGenerator.genSuccessResult(iTProjectService.insertOrUpdate(tProject));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索单个项目表
     * 传入项目id
     * */
    @GetMapping("/seachOneproject")
    Object seachOneproject(@RequestParam String project_id)throws Exception{
        try {
            return RestResultGenerator.genSuccessResult(iTProjectService.selectById(project_id));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 搜索项目表
     * 传入当前页
     * */
    @GetMapping("/seachproject/{page}")
    Object seachproject(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTProjectService.findProjectAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 字典表添加或修改
     * 传入对象
     * */
    @PostMapping("/dictionariesInsertOrUpdate")
    Object dictionariesInsertOrUpdate(@RequestBody TDictionaries tDictionaries)throws Exception{
        try {
            tDictionaries.setCreateTime(new Date());
            return RestResultGenerator.genSuccessResult(iTDictionariesService.insertOrUpdate(tDictionaries));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索单个字典表
     * 传入字典id
     * */
    @GetMapping("/seachOnedictionaries")
    Object seachOnedictionaries(@RequestParam Integer id)throws Exception{
        try {
            return RestResultGenerator.genSuccessResult(iTDictionariesService.selectById(id));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 搜索字典表
     * 传入当前页
     * */
    @GetMapping("/seachTDictionaries/{page}")
    Object seachTDictionaries(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTDictionariesService.findDictionariesAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 实体表添加或修改
     * 传入对象
     * */
    @PostMapping("/entityInsertOrUpdate")
    Object entityInsertOrUpdate(@RequestBody TEntity tEntity)throws Exception{
        try {
            tEntity.setCreateTime(new Date());
            return RestResultGenerator.genSuccessResult(iTEntityService.insertOrUpdate(tEntity));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索实体表
     * 传入当前页
     * */
    @GetMapping("/seachTEntity/{page}")
    Object seachTEntity(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTEntityService.findTEntityAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 接口添加或修改
     * 传入对象
     * */
    @PostMapping("/TInterfaceInsertOrUpdate")
    Object TInterfaceInsertOrUpdate(@RequestBody TInterface tInterface)throws Exception{
        try {
            tInterface.setCreateTimes(new Date());
            return RestResultGenerator.genSuccessResult(iTInterfaceService.insertOrUpdate(tInterface));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索接口表
     * 传入当前页
     * */
    @GetMapping("/seachTInterface/{page}")
    Object seachTInterface(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTInterfaceService.findTInterfaceAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 模块表添加或修改
     * 传入对象
     * */
    @PostMapping("/TModularInsertOrUpdate")
    Object TModularInsertOrUpdate(@RequestBody TModular tModular)throws Exception{
        try {
            tModular.setCreateTime(new Date());
            return RestResultGenerator.genSuccessResult(iTModularService.insertOrUpdate(tModular));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索模块表
     * 传入当前页
     * */
    @GetMapping("/seachTModular/{page}")
    Object seachTModular(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTModularService.findTModularAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }

    /**
     * 模块资源表添加或修改
     * 传入对象
     * */
    @PostMapping("/TResourceInsertOrUpdate")
    Object TResourceInsertOrUpdate(@RequestBody TResource tResource)throws Exception{
        try {
            tResource.setCreateTime(new Date());
            return RestResultGenerator.genSuccessResult(iTResourceService.insertOrUpdate(tResource));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("失败");
        }
    }

    /**
     * 搜索模块资源表
     * 传入当前页
     * */
    @GetMapping("/seachTResource/{page}")
    Object seachTResource(@PathVariable("page") Integer page)throws Exception{
        try {
            Page<List<Map<String,Object>>> pages=new Page<>();
            pages.setCurrent(page);
            pages.setSize(10);
            return RestResultGenerator.genSuccessResult(iTResourceService.findTResourceAll(pages));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("");
        }
    }
}
